<?php
$csvfile = "tpa.csv";
$outputfile = "tpa.sql";
$startindex = 1;

/***********************************************/
function processRow($counter, $rowdata, $out) {
    $country = $rowdata[0];
    $tpa = $rowdata[1];
    $contactperson = $rowdata[2];
    $position = $rowdata[3];
    $email1 = $rowdata[4];
    $email2 = $rowdata[5];

    $insert1 = "INSERT INTO lst_tpa (country, tpa, contactperson, position, email1, email2) ".
              "VALUES ('$country', '$tpa', '$contactperson', '$position', '$email1', '$email2');\r\n";
    fputs($out, $insert1);
}
/***********************************************/

$f = fopen($csvfile, "r");
$c = 0;
$out = fopen($outputfile,  "w");
$counter = $startindex;
while (!feof($f)) {
    $c++;
    $row = rtrim(fgets($f));
    if ($c == 1) { continue; }
    $row = str_replace("\"", "", $row);
    $row = str_replace("'", "''", $row);
    $rowdata = explode(";", $row);
    processRow($counter, $rowdata, $out);
    $counter++;
}
fclose($f);
fclose($out);
?>
